package migrations

import (
	"github.com/goravel/framework/contracts/database/schema"
	"github.com/goravel/framework/facades"
)

type M20250122062000CreateCategoriesTable struct {
}

// Signature The unique signature for the migration.
func (r *M20250122062000CreateCategoriesTable) Signature() string {
	return "20250122062000_create_categories_table"
}

// Up Run the migrations.
func (r *M20250122062000CreateCategoriesTable) Up() error {

	if !facades.Schema().HasTable("categories") {
		return facades.Schema().Create("categories", func(table schema.Blueprint) {
			table.ID()
			//table.Integer("tenant_id").Nullable().Default(0).Unsigned().Comment("租户id")
			table.String("name").Nullable().Comment("分类名")
			table.Integer("parent_id").Nullable().Default(0).Unsigned().Comment("上级id")
			table.BigInteger("sort").Nullable().Default(0).Comment("排序")
			table.TinyInteger("type").Nullable().Default(1).Unsigned().Comment("类型")
			table.TinyInteger("status").Default(1).Comment("1 显示 2 隐藏")
			table.Timestamps()
			table.SoftDeletes()

			table.Unique("name", "type", "deleted_at")

		})
	}

	return nil
}

// Down Reverse the migrations.
func (r *M20250122062000CreateCategoriesTable) Down() error {
	return facades.Schema().DropIfExists("categories")
}
